<template>
  <div class="container">
    <h2 class="handle-title">系统管理 > 机构管理</h2>
    <div class="handle-box">
      <div>
        <span class="search-label" style="margin-left: 5px">机构名字:</span>
        <el-input v-model="search" style="width: 120px" placeholder="请输入名字"></el-input>
        <span class="search-label" style="margin-left: 5px">机构状态:</span>
        <el-select v-model="value" style="width: 120px">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-button class="query_btn" type="primary" @click="goSearch">查询</el-button>
        <el-button class="query_btn" type="primary" @click="addOrg">添加</el-button>
      </div>
    </div>
    <el-table
      :data="tableData"
      class="table"
      border>
      <el-table-column prop="orgname" label="名称" />
      <el-table-column prop="orgaddr" label="地址" />
      <el-table-column prop="orgcontacts" label="法定代表人" />
      <el-table-column prop="orgphone" label="联系电话" />
      <el-table-column label="操作" width="200">
        <template #default="{row}">
          <el-button type="text" icon="el-icon-edit-outline" @click="goUpdate(row.orgid)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="totalNum">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {getOrganization} from "../../api/public/api";

export default {
  name: '',
  data() {
    return {
      value:"-1", //状态选择默认为 -1 表示全部
      options:[
        {
          value: '-1',
          label: '全部'
        },
        {
          value: '1',
          label: '可用'
        },
        {
          value: '0',
          label: '不可用'
        }
      ],
      tableData: [], //数据列表
      currentPage: 1, //默认第一页
      pageSize: 10, //默认每页10条
      totalNum: 0, //默认总条数
      search: "", //搜索名字
    }
  },
  mounted() {
    //获取角色管理数据初始值
    this.roleList()
  },
  methods:{
    //每页条数
    handleSizeChange(val) {
      this.pageSize=val;
      this.roleList()
    },
    // 第几页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.roleList()
    },
    //封装请求方法
    roleList(){
      let params ={
        pagenum:this.currentPage,
        pagesize:this.pageSize,
      }
      if(this.search){
        params.orgname=this.search;
      }
      getOrganization(params).then((res)=>{
        // console.log(res)
        this.tableData = res.data.pagedata.records;
        this.totalNum = res.data.pagedata.total;
      })
    },
    //Search搜索按钮
    goSearch(){
      this.roleList()
    },
    //修改
    goUpdate(id){
      // console.log(id)
      this.$router.push({
        path:"/updateOrg",
        query:{id}
      })
    },
    //权限管理
    goRight(id){
      this.$router.push({
        path:"/right",
        query:{id}
      })
    },
    // 添加机构
    addOrg(){
      this.$router.push({
        path:'/addOrg'
      })
    }
  },

}
</script>

<style>
.handle-title{
  line-height: 50px;
}
</style>
